//
//  DetailsController.m
//  网易新闻
//
//  Created by dllo on 15/9/23.
//  Copyright (c) 2015年 Lx. All rights reserved.
//

#import "DetailsController.h"
#import "AFTool.h"
#import "BBSController.h"
#import "MenuView.h"
@interface DetailsController ()
@property(nonatomic, retain)UIButton *bbs;
@property(nonatomic, retain)UIButton *setting;
@property(nonatomic, retain)MenuView *menu;
@end

@implementation DetailsController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.tabBarController.tabBar.hidden = YES;
    self.bbs.hidden = NO;
    self.setting.hidden = NO;
}
- (void)viewWillDisappear:(BOOL)animated{
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    self.tabBarController.tabBar.hidden = NO;
    self.bbs.hidden = YES;
    self.setting.hidden = YES;
    if (!self.menu.hidden) {
        self.menu.hidden = YES;
    }
}

- (void)handData{
    [AFTool GETWithURL:[NSString stringWithFormat:@"http://c.m.163.com/nc/article/%@/full.html", self.docid] body:nil httpHead:nil responseStyle:JSON success:^(id result) {
        NSDictionary *tempDic = [[NSDictionary alloc]initWithDictionary:result];
        self.mod = [DetailsModel modWithDic:[tempDic objectForKey:self.docid]];
        [tempDic release];
        [self createSelf];
        [self createButton];
        [self createSetButton];
        [self createMenu];
    } fail:^(NSError *error) {
        NSLog(@"404(DetailsController)");
    }];
}

- (void)createButton{
    self.bbs = [UIButton buttonWithType:UIButtonTypeSystem];
    self.bbs.frame =CGRectMake(240, 10, 75, 25);
    self.bbs.backgroundColor = [UIColor redColor];
    [self.bbs setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.bbs setTitle:[NSString stringWithFormat:@"%lu跟帖", self.mod.replyCount] forState:UIControlStateNormal];
    [self.bbs addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationController.navigationBar addSubview:self.bbs];
}

- (void)click:(UIButton *)button{
    BBSController *bbs = [[BBSController alloc]init];
    bbs.replyBoard = self.mod.replyBoard;
    bbs.docid = self.docid;
    [self.navigationController pushViewController:bbs animated:YES];
    [bbs release];
}

- (void)createSetButton{
    self.setting = [UIButton buttonWithType:UIButtonTypeSystem];
    self.setting.frame =CGRectMake(340, 10, 25, 25);
    [self.setting setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.setting setTitle:@"···" forState:UIControlStateNormal];
    [self.setting addTarget:self action:@selector(clickSetting:) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationController.navigationBar addSubview:self.setting];
}

- (void)createMenu{
    self.menu = [[MenuView alloc]init];
    self.menu.mod = self.mod;
    self.menu.docid = self.docid;
    [self.view addSubview:self.menu];
    [self.menu release];
}

- (void)clickSetting:(UIButton *)button{
    [self.menu popView];
}

- (void)dealloc{
    [_menu release];
    [super dealloc];
}
@end

